package ar.com.globallogic.promomr.persistance;

import java.util.List;

import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import ar.com.globallogic.promomr.domain.Image;

@Repository
public interface ImageRepository extends CrudRepository<Image, String>{
	
	@Query(value="{$and: [" +
					"{'_class': 'ar.com.globallogic.promomr.domain.Image'}, " +
					"{$or:[{$where:'?0==null'},{name: ?0}]}, " +
					"{$or:[{$where:'?1==null'},{description: ?1}]}, " +
					"{$or:[{$where:'?2.length==0'},{labels.name: {$all: ?2}}]} " +
				"]}",
		   fields="{id : 1}") 
	public List<Image> findByProperties(String name, String description, List<String> labels);

}
